package com.chilly.other.collection;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * hashMap+双向链表
 * Created by Chilly Cui on 2020/11/26.
 */
public class LinkedHashMapDemo {
    public static void main(String[] args) {

        //按照插入顺序的
        Map<String, Integer> seqMap = new LinkedHashMap<>();
        seqMap.put("c", 100);
        seqMap.put("d", 200);
        seqMap.put("a", 500);
        seqMap.put("d", 300);
//        for (Map.Entry<String, Integer> entry : seqMap.entrySet()) {
//            System.out.println(entry.getKey() + " " + entry.getValue());
//        }

        //按访问顺序的栗子：
        Map<String, Integer> accessMap = new LinkedHashMap<>(16, 0.75f, true);
        accessMap.put("c", 100);
        accessMap.put("d", 200);
        accessMap.put("a", 500);
        accessMap.put("b", 500);
        accessMap.get("c");
        accessMap.get("c");
        accessMap.get("c");
        accessMap.put("d", 300);
        for (Map.Entry<String, Integer> entry : accessMap.entrySet()) {
            System.out.println(entry.getKey() + " " + entry.getValue());
        }

    }
}
